import requests

# 下载图片
"""
with open('test001.jpg', 'w') as f:
    r = requests.get('https://imgm.gmw.cn/attachement/jpg/site215/20200203/7331387326140037126.jpg')
    # f.write(r.content)
    for chunk in r.iter_content(512):
        f.write(chunk)
"""
# 解压返回的HTML数据
'''
r = requests.get('https://www.163.com', stream=True)
if r.headers['Content-Encoding'] == 'gzip':
    import gzip

    data = gzip.decompress(r.raw.read())
    print(data)
'''
# 压缩数据
import gzip

data = 'this is data to be compressed'
data = data * 500
compressed_data = gzip.compress(data.encode('utf-8'))

print(len(data))
print(len(compressed_data))
